#include <stdio.h>
#include <stdlib.h>

#define kMaxN 30
typedef enum { false, true } bool;
typedef int TElemSet; /* 默认元素为整型 */
typedef enum { Red, Black } Color;
typedef struct RBTreeNode *Position; /* 树结点指针是元素的位置 */
typedef struct RBTreeNode *RBTree;
struct RBTreeNode {
    TElemSet data; /* 数据元素 */
    RBTree left; /* 左孩子指针 */
    RBTree right; /* 右孩子指针 */
    Color color; /* 颜色 */
    int black_height; /* 结点黑高 */
};

int CmpNum(const void *a, const void *b) {
    return ((*(const int*)a) < (*(const int*)b)) ? -1 : 1;
}

RBTree BuildTree(TElemSet *preorder, TElemSet *inorder, int n) {
    /* 根据前序遍历序列和中序遍历序列构建有n个结点的二叉树 */
    RBTree tree;
    int i;

    if (n == 0) {
        tree = NULL; /* 递归终止条件，空树 */
    } else {
        /* 建立当前根结点 */
        tree = (RBTree)malloc(sizeof(struct RBTreeNode));
        tree->black_height = 0; /* 初始化黑高为0 */
        /* 确定结点颜色 */
        if (preorder[0] < 0) {
            tree->color = Red;
            preorder[0] = -preorder[0];
        } else {
            tree->color = Black;
        }
        tree->data = preorder[0];
        /* 在中序遍历序列中找根结点 */
        for (i = 0; i < n; i++) {
            if (inorder[i] == preorder[0])
                break;
        }
        /* 递归构建左右子树 */
        tree->left = BuildTree(preorder + 1, inorder, i);
        tree->right = BuildTree(preorder + i + 1, inorder + i + 1, n - i - 1);
    }
    return tree;
}

bool Check(RBTree tree) {
    int left_bh, right_bh;
    bool ret;

    ret = true; /* 初始化返回值为真 */
    left_bh = right_bh = 0; /* 初始化左右子树黑高为0 */
    if (tree != NULL) { /* 检查非空树 */
        if (tree->color == Black) {
            tree->black_height = 1; /* 初始化黑结点的黑高为1 */
        } else { /* 检查红结点的孩子是否为黑 */
            if (tree->left != NULL && tree->left->color == Red) {
                ret = false;
            }
            if (tree->right != NULL && tree->right->color == Red) {
                ret = false;
            }
        }
        if (ret == true && (tree->left != NULL || tree->right != NULL)) {
            /* 检查左右子树的黑高 */
            if (Check(tree->left) == true && Check(tree->right) == true) {
                if (tree->left != NULL) {
                    left_bh = tree->left->black_height;
                }
                if (tree->right != NULL) {
                    right_bh = tree->right->black_height;
                }
                if (left_bh == right_bh) {
                    tree->black_height += left_bh; /* 更新根结点黑高 */
                } else {
                    ret = false; /* 左右黑高不等 */
                }
            } else {
                ret = false; /* 左右子树有问题 */
            }
        }
    }
    return ret;
}

void DestroyTree(RBTree tree) {
    if (tree != NULL) {
        DestroyTree(tree->left);
        DestroyTree(tree->right);
        free(tree);
    }
}

int main(void) {
    int k, n, i;
    TElemSet preorder[kMaxN], inorder[kMaxN];
    RBTree tree;

    scanf("%d", &k);
    while (k--) {
        scanf("%d", &n);
        for (i = 0; i < n; i++) {
            scanf("%d", &preorder[i]);
        }
        if (preorder[0] < 0)
            printf("No\n"); /* 根结点是红色 */
        else {
            for (i = 0; i < n; i++) {
                inorder[i] = (preorder[i] > 0) ? preorder[i] : (-preorder[i]);
            }
            qsort(inorder, n, sizeof(int), CmpNum);
            tree = BuildTree(preorder, inorder, n);
            if (Check(tree) == true) {
                printf("Yes\n");
            } else {
                printf("No\n");
            }
            DestroyTree(tree);
        }
    }
    return 0;
}